//sync
#include <stdio.h>
#include "rediscluster.h"

//sync
int main()
{
	int result;
	redisReply *reply = NULL;

#if 1
	redisClusterContext *cc = redisClusterConnect("192.168.3.97:7000,192.168.3.97:7001,192.168.3.97:7002", "pass123", HIRCLUSTER_FLAG_NULL);
#else
	redisClusterContext *cc = redisClusterContextInit();
	redisClusterSetOptionPassword(cc, "pass123");
	redisClusterSetOptionAddNodes(cc, "192.168.3.97:7000,192.168.3.97:7001,192.168.3.97:7002");
	redisClusterConnect2(cc);
#endif

	if (cc == NULL || cc->err)
	{
		printf("connect error : %s\n", cc == NULL ? "NULL" : cc->errstr);
		return -1;
	}

	printf("Connect to redisServer Success\n");

	int i;
	for (i = 0; i < 5; i++)
	{
		//set
		reply = (redisReply*)redisClusterCommand(cc, "set key%d value%d", i, i);
		if (reply == NULL)
		{
			printf("set key%d, reply is NULL, error info: %s\n", i, cc->errstr);
			redisClusterFree(cc);
			return -1;
		}
		printf("set key%d, reply:%s\n", i, reply->str);
		freeReplyObject(reply);

		//get
		reply = (redisReply*)redisClusterCommand(cc, "get key%d", i);
		if (reply == NULL)
		{
			printf("get key%d, reply is NULL, error info: %s\n", i, cc->errstr);
			redisClusterFree(cc);
			return -1;
		}
		printf("get key%d, reply:%s\n", i, reply->str);
		freeReplyObject(reply);
	}

	redisClusterFree(cc);
	getchar();
	return 0;
}
